import baseUrl from "@/api/baseUrl";
import request from "@/utils/request";

export function ok(token) {
    return request({
        url: baseUrl + "index/order/ok",
        method: 'post',
        headers: {
            Authorization: token
        }
    })
}

export function alipay(token, gameId, gameName, goodsType, price) {
    return new Promise((resolve, reject) => {
        request({
            url: baseUrl + "order/alipay?gameId=" + gameId + '&gameName=' + gameName + '&goodsType=' + goodsType + '&price=' + price,
            method: 'post',
            headers: {
                Authorization: token,
                // gameId: gameId,
                // gameName: gameName,
                // goodsType: goodsType,
                // price: price,
            }
        }).then(response => {
            resolve(response)
        }).catch(error => {
            reject(error)
        })
    })
}

export function top_up_alipay(token, goodsType, price) {
    return new Promise((resolve, reject) => {
        request({
            url: baseUrl + 'order/alipay?goodsType=' + goodsType + '&price=' + price,
            method: 'post',
            headers: {
                Authorization: token,
                // gameId: gameId,
                // gameName: gameName,
                // goodsType: goodsType,
                // price: price,
            }
        }).then(response => {
            resolve(response)
        }).catch(error => {
            reject(error)
        })
    })
}

export function alipayNotify(token) {
    return request({
        url: baseUrl + "order/notify",
        method: 'post',
        headers: {
            Authorization: token
        }
    })
}

export function payAgain(token, orderId) {
    return request({
        url: baseUrl + "order/payAgain",
        method: 'get',
        headers: {
            Authorization: token,
            orderId: orderId,
        }
    })
}

export function pay_by_balance(token, gameId) {
    return new Promise((resolve, reject) => {
        request({
            url: baseUrl + "order/payByBalance?gameId=" + gameId,
            method: 'get',
            headers: {
                Authorization: token,
            }
        }).then(response => {
            resolve(response)
        }).catch(error => {
            reject(error)
        })
    })
}

export function selectOrder(token) {
    return request({
        url: baseUrl + "order/selectOrder",
        method: 'get',
        headers: {
            Authorization: token,
        }
    })
}